/*
Table 3: Informal Safety Nets
*/

est clear
version 14.0
set more off


// DATA
use "household_level_final.dta", clear
iis hid_base

// Construct deflated transfer amount vars for imbalanced baseline values

foreach x in trans_from_tot 	    trans_from_ind {
loc labl: var label `x'
	replace `x'=`x'/1000
	label var `x' "`labl' (1000s TSH)"
	
	clonevar `x'_09cons=`x'
	replace `x'_09cons=`x'_09cons/1.196777893 if period==2
	replace `x'_09cons=`x'_09cons/1.388277649 if period==3
	label var `x'_09cons "`labl' in 1000s cons. 2009 TSH"
}

// OUTCOMES AND CONTROL VECTORS (VARIABLES IMBALANCED AT BASELINE)
loc outcomes = 	"dm_could_get15k		dm_could_get_childcare 	dm_came_for_assistance	"
loc imbalancedvars = "improvedfloor_b	dm_trust_comm	dm_food_from_ind	trans_from_tot_09cons	trans_from_ind_09cons	"

#delimit ;
	loc hh_lev_controls	= "
	age_head_b		
	age2_head_b			
	sex_head_b		
	dm_lowerprimed_head_b	
	dm_uppered_head_b	
	dm_literate_head_b
	HHqty_b_FE_1 	
	HHqty_b_FE_2 		
	HHqty_b_FE_3 		
	HHqty_b_FE_4 		
	HHqty_b_FE_5 		
	HHqty_b_FE_6
	HHqty_b_FE_7 	
	HHqty_b_FE_8 		
	HHqty_b_FE_9 		
	HHqty_b_FE_10		
	HHqty_b_FE_11 		
	HHqty_b_FE_12
	improvedroof_b 	
	improvedfloor_b 	
	improvedtoilet_b 	
	pipedwater_b		
	pca_assets" ;
	
	loc vil_lev_controls	= "
	Dist_FE_2 
	Dist_FE_3 
	log_pop"		;	
#delimit cr	


// REGRESSIONS

//without HTE, controlling for variables imbalanced at baseline interacted with a time trend

foreach y in `imbalancedvars' {
	clonevar temp= `y'
	replace temp=. if period!=1
	bysort hid_base: egen `y'_b=max(temp)
	loc labb: var label `y'
	gen imb_`y'_b_pd2=`y'_b*dmpd2
	label var imb_`y'_b_pd2 "BL val of `labb' x pd 2"
	gen imb_`y'_b_pd3=`y'_b*dmpd3
	label var imb_`y'_b_pd3 "BL val of `labb' x pd 3"
	drop temp 
}

qui foreach y in `outcomes' {
	eststo: reg 	`y'		assignedtotreat3	`hh_lev_controls'	`vil_lev_controls' 	dm_trust_comm_b	dm_food_from_ind_b	trans_from_tot_09cons_b	trans_from_ind_09cons_b,  cluster(CLID)
}
noi estout *, cells(	b(fmt(%9.3f)star)	se(fmt(%9.3f)) 	) 	stats(N r2,fmt(0 3)) starlevels(* 0.10 ** 0.05 *** 0.01) 

esttab using Table3.csv, b(3) se(3) r2 starlevels(* 0.1 ** .05 *** .01) obslast replace


est clear

exit

